#include "TipLayer.h"

bool TipLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();
	m_tips = Text::create("", "game/common/fzcy.TTF", 60);
	m_tips->setColor(Color3B::BLACK);
	m_tips->setTextHorizontalAlignment(TextHAlignment::CENTER);
	m_tips->ignoreContentAdaptWithSize(false);
	m_tips->setSize(Size(600, 300));
	m_tips->setPosition(Vec2(origin.x + visibleSize.width / 2
		, origin.y + visibleSize.height / 2));
	m_tips->setZOrder(887);
	this->addChild(m_tips);

	m_alert = ImageView::create("scene/res/20170517-swipeCard.png");
	m_alert->setScale9Enabled(true);
	m_alert->setSize(Size(756, 472));
	m_alert->setPosition(Vec2(origin.x + visibleSize.width / 2
		, origin.y + visibleSize.height / 2));
	m_alert->setOpacity(0);
	addChild(m_alert);

	return true;
}

void TipLayer::tip(const char* tips)
{
	m_tips->setOpacity(255);
	m_tips->setText(tips);
	FadeOut * tinto = FadeOut::create(3);
	m_tips->runAction(tinto);
}

void TipLayer::tip(const char* tips, const Color3B& color)
{
	m_tips->setOpacity(255);
	m_tips->setText(tips);
	m_tips->setColor(color);
	FadeOut * tinto = FadeOut::create(3);
	m_tips->runAction(tinto);
}

void TipLayer::alert(int errorCode)
{
	m_alert->setOpacity(255);
	FadeOut * tinto = FadeOut::create(3);
	m_alert->runAction(tinto);
	AudioEngine::play2d(String::createWithFormat("%s/reSwipeCard.mp3", GlobalData::getInstance()->getSoundPath().c_str())->getCString());
}